//
//  UIView+EXExtension.m
//  MobileProject
//
//  Created by caiqilin on 2016/10/31.
//  Copyright © 2016年 caiqilin. All rights reserved.
//

#import "UIView+EXExtension.h"

@implementation UIView (EXExtension)
- (CGSize)ex_size {
    return self.frame.size;
}

-(void)setEx_size:(CGSize)ex_size {
    CGRect frame = self.frame;
    frame.size = ex_size;
    self.frame = frame;
}

- (CGFloat)ex_width {
    return self.frame.size.width;

}

- (CGFloat)ex_height {
    return self.frame.size.height;
}

- (void)setEx_width:(CGFloat)ex_width {
    CGRect frame = self.frame;
    frame.size.width = ex_width;
    self.frame = frame;
}

- (void)setEx_height:(CGFloat)ex_height {
    CGRect frame = self.frame;
    frame.size.height = ex_height;
    self.frame = frame;
}

- (CGFloat)ex_x {
    return self.frame.origin.x;

}

- (void)setEx_x:(CGFloat)ex_x {
    CGRect frame = self.frame;
    frame.origin.x = ex_x;
    self.frame = frame;
}

- (CGFloat)ex_y {
    return self.frame.origin.y;

}

- (void)setEx_y:(CGFloat)ex_y {
    CGRect frame = self.frame;
    frame.origin.y = ex_y;
    self.frame = frame;
}

- (CGFloat)ex_centerX {
    return self.center.x;

}

- (void)setEx_centerX:(CGFloat)ex_centerX {
    CGPoint center = self.center;
    center.x = ex_centerX;
    self.center = center;
}

- (CGFloat)ex_centerY {
    return self.center.y;

}

- (void)setEx_centerY:(CGFloat)ex_centerY {
    CGPoint center = self.center;
    center.y = ex_centerY;
    self.center = center;
}

- (CGFloat)ex_right {
    //    return self.xmg_x + self.xmg_width;
    return CGRectGetMaxX(self.frame);
}

- (CGFloat)ex_bottom {
    //    return self.xmg_y + self.xmg_height;
    return CGRectGetMaxY(self.frame);
}

- (void)setEx_right:(CGFloat)ex_right {
    self.ex_x = ex_right - self.ex_width;

}

- (void)setEx_bottom:(CGFloat)ex_bottom {
    self.ex_y = ex_bottom - self.ex_height;

}


+ (instancetype)viewFromXib
{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
}

- (BOOL)intersectWithView:(UIView *)view
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    CGRect selfRect = [self convertRect:self.bounds toView:window];
    CGRect viewRect = [view convertRect:view.bounds toView:window];
    return CGRectIntersectsRect(selfRect, viewRect);
}
@end
